home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / WLIB.ZIP / WDBASE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-20  |  6.4 KB  |  171 lines

  1. #ifndef WDBaseIncluded
  2. #define WDBaseIncluded
  3.  
  4. // copyright (c) 1992, 1993 by Paul Wheaton
  5. // 1916 Brooks #205, Missoula, MT  59801
  6. //
  7. //       phone:  (406)543-1928
  8. //  CompuServe:  72707,207
  9. //    Internet:  72707.207@CompuServe.com
  10.  
  11. #define S4FOX
  12. //#define S4DEBUG
  13.  
  14. #include <d4all.h>
  15.   // codebase stuff - if you don't have CodeBase, don't compile WDBASE.C
  16. #include <WStr.h>
  17. #include <WTime.h>
  18. #include <WVec.h>
  19.  
  20. String40 DateToDbase(const Date&);
  21. Date     DbaseToDate(const char*);
  22.  
  23. void DBaseAutoOpen(Bool OnOff);  // turn the index "auto-open" feature on and off
  24.  
  25. class Field
  26.   {
  27.       F4FIELD* F;
  28.     public:
  29.       Field(F4FIELD* FF){F=FF;}
  30.       void operator=(const char* St){f4assign(F,(char*)St);}
  31.       void Assign(const char* St){f4assign(F,(char*)St);}
  32.       operator const char*(){return f4str(F);}
  33.       operator String() {return String(f4str(F));}
  34.       String St() {return String(f4str(F));}
  35.  
  36.       void operator=(double D){f4assign_double(F,D);}
  37.       void Assign(double D){f4assign_double(F,D);}
  38.       operator double(){return f4double(F);}
  39.       double D(){return f4double(F);}
  40.  
  41.       void operator=(int I){f4assign_int(F,I);}
  42.       void Assign(int I){f4assign_int(F,I);}
  43.       operator int(){return f4int(F);}
  44.       int I(){return f4int(F);}
  45.  
  46.       void operator=(long L){f4assign_long(F,L);}
  47.       void Assign(long L){f4assign_long(F,L);}
  48.       operator long(){return f4long(F);}
  49.       long L(){return f4long(F);}
  50.  
  51.       // void operator=(Bool B){f4assign_char(F,(B?'T':'F'));}
  52.       void AssignBool(Bool B){f4assign_char(F,(B?'T':'F'));}
  53.       // operator Bool(){return f4true(F);}
  54.       Bool B(){return f4true(F);}
  55.  
  56.       void operator=(const Date& D){f4assign(F,(char*)(const char*)DateToDbase(D));}
  57.       void Assign(const Date& D){f4assign(F,(char*)(const char*)DateToDbase(D));}
  58.       operator Date(){return DbaseToDate(f4str(F));}
  59.       //Date D(){return DbaseToDate(f4str(F));}
  60.  
  61.       void Blank(){f4blank(F);}
  62.       const char* Name(){return f4name(F);}
  63.       int Len(){return f4len(F);}
  64.   };
  65.  
  66. typedef F4FIELD* FieldStar;
  67.  
  68. CreateAtomicVectorClass(DBaseFieldVector,FieldStar);
  69.  
  70. class DBase
  71.   {
  72.       D4DATA* D;  //  points to the data CodeBase keeps on this database
  73.       DBaseFieldVector V;
  74.       Bool Closed;
  75.     public:
  76.       DBase(const char* FileName);
  77.       ~DBase()                              {Close();}
  78.       operator D4DATA*(){return D;}
  79.       void Close();
  80.       void Top()                            {d4top(D);}
  81.       void Bottom()                         {d4bottom(D);}
  82.       Bool bof()                            {return (d4bof(D)!=0);}
  83.       Bool eof()                            {return (d4eof(D)!=0);}
  84.         // "EOF" (vs. "eof") will not work due to conflict with ANSI lib "EOF"
  85.       void Delete()                         {d4delete(D);}
  86.       Bool Deleted()                        {return d4deleted(D);}
  87.       long RecNum()                         {return d4recno(D);}
  88.       void GetRec(long R)                   {d4go(D,R);}
  89.       Field F(const char* FieldName)        {return d4field(D,(char*)FieldName);}
  90.       Field F(int FieldNum)                 {return V(FieldNum);}
  91.       int FieldNum(const char* FieldName)   {return d4field_number(D,(char*)FieldName);}
  92.       int NumFields()                       {return d4num_fields(D);}
  93.       long NumRecs()                        {return d4reccount(D);}
  94.       int Seek(const char* SearchText)      {return d4seek(D,(char*)SearchText);}
  95.       int Seek(long SearchVal)         {return d4seek(D,(char*)(const char*)Str(SearchVal));}
  96.       Bool Skip(long Num=1)                 {return (d4skip(D,Num)==0);}
  97.       void SetIndexTag(const char* TagName);
  98.       void SetDefaultTag() {d4tag_default(D);}
  99.       void AppendBlank() {d4append_blank(D);}
  100.       void AppendStart(Bool UseMemo=True) {d4append_start(D,UseMemo);}
  101.       void Blank(){d4blank(D);}
  102.       double Percent() {return d4position(D);}
  103.       void Flush(){d4flush_record(D);}
  104.       void FlushAll(){d4flush_all(D);}  // flushes indexes too
  105.       T4TAG* Tag(const char* TagName=NULL);
  106.         // if NULL is passed, the default is used
  107.   };
  108.  
  109. class DBaseTag
  110.   {
  111.       T4TAG* T;
  112.     public:
  113.       DBaseTag(DBase& DB,const char* Tag=NULL){T=DB.Tag(Tag);}
  114.       Bool Top()                            {return (t4top(T)==0);}
  115.       void Bottom()                         {t4bottom(T);}
  116.       Bool eof()                            {return (t4eof(T)!=0);}
  117.       long Skip(long Num=1)                 {return t4skip(T,Num);}
  118.         // returns number skipped (note that eof is weird with Skip)
  119.       double Percent()                      {return t4position(T);}
  120.       long RecNum()                         {return t4recno(T);}
  121.       int Seek(const char* SearchText)      {return t4seek(T,(char*)SearchText,strlen(SearchText));}
  122.       int Seek(long SearchVal)         {return t4seek(T,&SearchVal,4);}
  123.   };
  124.  
  125. // internal use only
  126. CreateRefVectorClass(CDBFVector,F4FIELD_INFO);
  127. CreateRefVectorClass(CDBTVector,T4TAG_INFO);
  128.  
  129. extern const char* NotDeleted; // =".NOT. DELETED()";
  130.  
  131. const int DBAscending=0;
  132. const int DBDescending=r4descending;
  133.  
  134. class CreateDBaseFile // a DBase file is created and closed
  135.   {
  136.       CDBFVector FV;
  137.       CDBTVector TV;
  138.       String120 Name;
  139.     public:
  140.       CreateDBaseFile(const char* FileName){Name=FileName;}
  141.       ~CreateDBaseFile(){Done();}
  142.       void DefineField(const char* FieldName,char Type='C',int Width=20,int Decimals=0);
  143.       void DefineTag(const char* TagName, const char* KeyExpression,
  144.           const char* FilterExpression=NotDeleted, int Unique=0, int Descending=0);
  145.       void Done();
  146.   };
  147.  
  148. class CreateDBaseIndex
  149.   {
  150.       DBase* DB;
  151.       CDBTVector TV;
  152.       String120 Name;
  153.       Bool Finished;
  154.     public:
  155.       CreateDBaseIndex(DBase& D,const char* IndexFileName=NULL);
  156.       ~CreateDBaseIndex(){Done();}
  157.       void DefineTag(const char* TagName, const char* KeyExpression,
  158.           const char* FilterExpression=NotDeleted, int Unique=0, int Descending=0);
  159.       void Done();
  160.         // deletes IndexFileName (if it exists) and creates an index.
  161.         // re-indexes on all tags.  sets active index to the first tag given
  162.   };
  163.  
  164. void CreateADBaseIndex(DBase& DB,const char* IndexFileName,const char* TagName,
  165.     const char* KeyExpression,const char* FilterExpression=NotDeleted,
  166.     int Unique=0,int Descending=0);
  167.   // deletes IndexFileName (if it exists) and creates an index.
  168.   // re-indexes.  sets active index to TagName
  169.  
  170. #endif
  171.